<?php 

   /**
    *
    * FILE:          cieListAll.php
    * LOCATION:      /root
    * REFERENCES:    admin.php
    *                cieSearch.php
    *                cieEdit.php
    * FUNCTION:      displays a table of consumers that are
    *                returned from the database as a resultset
    *                based on search parameters from cieSearch.php
    * DEPENDENCIES:  db_connect.php 
    * 
    * --> LAST CODE MERGE FROM HALFSLIDE:  9-26-07
    * ==============================================================================
    * 
    * @version $Id: admin.php,v 0.1 2007/09/3
    * @copyright Copyright (c) none
    * @author Peter Holcomb
    * @license http://opensource.org/licenses/gpl-license.php GNU General 
    * Public License Version 2 (GPL v2)
    * 
    * ==============================================================================
    */
    
   //connect to database
	include('includes/db_connect.php');
	include_once('./classes/pagination.class.php');
       

        //main pagination settings
	$items = 10;
	$page = 1;


	 //BEGIN PAGINATION CODE
         //THIS BLOCK HANDLES EMPTY SEARCH STRING

	
             if(isset($_GET['page']) and is_numeric($_GET['page']) and $page = $_GET['page']){

			$limit = " LIMIT ".(($page-1)*$items).",$items";

             }else{

			$limit = " LIMIT $items";
             }

	
	     //$sqlStr = "SELECT * FROM consumer";

              $sqlStr = "SELECT c.id, 
                                c.last_name, 
                                c.first_name, 
                                c.city, 
                                c.phone, 
                                c.address, 
                                c.zip, 
                                c.phone, 
                                ls.name as state
                          FROM   consumer c, 
                                 lst_state ls 
                          WHERE  c.state_id = ls.id 
                          ORDER BY c.last_name asc";

	      $sqlStrAux = "SELECT count(*) as total FROM consumer";



	      $aux = Mysql_Fetch_Assoc(mysql_query($sqlStrAux));
	      $query = mysql_query($sqlStr.$limit);

	      if($aux['total']>0){
			$p = new pagination;
			$p->Items($aux['total']);
			$p->limit($items);
			$p->target("admin.php?action=cielistall");
			$p->currentPage($page);
			$p->calculate();
			$p->changeClass("pagination");

                        $p->show();

			
?>

                <!-- THIS TABLE EDITED ON 10-3-07 TO RENDER NEW TABLE STYLE -->
                <!-- SET UP TABLE  FOR FULL RESULTSET-->
                <table class="table1">
                   <thead> 
                      <tr>
                         <th>Full Name</th>
                         <th>Address</th>
                         <th>City</th>
                         <th>State</th>
                         <th>Zip</th>
                         <th>Phone</th>
                     </tr>
                  </thead>
                  <tbody>
  

<?php

                  while($row = mysql_fetch_assoc($query)){
	  
                        if($i%2==0) {
		 
                          echo "<tr class='even'>";
	
                        }else {
	    
                          echo "<tr class='odd'>";
	      
                        }
?>

                        <!-- USER CAN CLICK ON FIRST OR LAST NAME TO VIEW CONSUMER CASE FILE INFO -->
                        <!-- changed to fullname on 10-3-07 -->

                        <td>
                            <a href="admin.php?action=cieedit&id=<?php echo $row["id"]; ?>">
                                 <?php echo $row["last_name"].", ".$row["first_name"]; ?>
                            </a>
                        </td>
                        <td><?php echo $row["address"]; ?></td>
                        <td><?php echo $row["city"]; ?></td>
                        <td><?php echo $row["state"]; ?></td>
                        <td><?php echo $row["zip"]; ?></td>
                        <td><?php echo $row["phone"]; ?></td>
                   </tr>
                </tbody>

<?php

                $i++;
             
              }  //END WHILE recordset fetch
?>
              </table>
              <!-- END RESULTSET TABLE -->
<?php

	      $p->show();

         }else{
		echo "There no are records to paginate.";
         } //ENDS routine for EMPTY SEARCH STRING

?>
   <br/>

<!-- USER HAS OPTION TO CREATE NEW CONSUMER CASE FILE -->
<p style="text-align:right;">
	<a style="border-top:1px #ccc dotted" href="admin.php?action=cieedit&id=0"><strong>Create New Case File</strong></a>
</p>